﻿Imports Microsoft.Win32
Imports System
Imports System.Windows.Forms

Public Class Factory

    Public Sub RemoveFileAssociation(ByVal extension As String)

        Dim key As RegistryKey
        key = Registry.CurrentUser

        extension = "." + extension

        With key.OpenSubKey("Software\Classes", True)
            .DeleteSubKey(extension)
            .DeleteSubKey(extension.Remove(0, 1) + "\shell\open\command")
        End With

        key.Close()

    End Sub

    Public Sub SetFileAssociation(ByVal extension As String)

        Dim key As RegistryKey
        key = Registry.CurrentUser

        extension = "." + extension

        With key.OpenSubKey("Software\Classes", True)
            .CreateSubKey(extension).SetValue("", extension.Remove(0, 1), Microsoft.Win32.RegistryValueKind.String)
            .CreateSubKey(extension.Remove(0, 1) + "\shell\open\command").SetValue("", Application.ExecutablePath & _
        " ""%l"" ", Microsoft.Win32.RegistryValueKind.String)
        End With

        key.Close()

    End Sub

End Class
